package com.zego.wawaji.ui.store.car;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zego.wawaji.R;
import com.zego.wawaji.ui.base.BaseAppCompatActivity;
import com.zego.wawaji.ui.base.CustomFrameLayout;
import com.zego.wawaji.ui.base.recycler.swipe.SwipeMenuRecyclerView;
import com.zego.wawaji.ui.bean.wawa.WawaJiList;
import com.zego.wawaji.ui.store.car.adapter.StoreCarAdapter;
import com.zego.wawaji.ui.store.car.adapter.StoreRecommendAdapter;

import java.util.ArrayList;

/**
 * 购物车
 * Created by Su on 2018/1/8.
 */
public class StoreCarActivity extends BaseAppCompatActivity implements View.OnClickListener {
    private CustomFrameLayout customLayout;
    private StoreCarAdapter carAdapter;
    private WawaJiList data;

    // 购物车列表
    private SwipeMenuRecyclerView carList;

    // 推荐列表
    private RecyclerView recommendList;
    private StoreRecommendAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        isCanBack(false);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store_car_activity);
        initView();
    }

    private void initView() {
        setBackView();
        setTitle("购物车");

        data = getIntent().getParcelableExtra("data");
        findViewById(R.id.nodata_btn).setOnClickListener(this);
        customLayout = (CustomFrameLayout) findViewById(R.id.customLayout);
        customLayout.show(R.id.car_no_data);

        initCarList();
        initRecommendList();
    }

    // 购物车商品
    private void initCarList() {
        carList = (SwipeMenuRecyclerView) findViewById(R.id.car_list);
        carList.setLayoutManager(new LinearLayoutManager(this));
        carAdapter = new StoreCarAdapter( );
        carList.setAdapter(carAdapter);
        customLayout.show(R.id.car_list);
        ArrayList<String> test = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            test.add("商品：" + i);
        }
        carAdapter.setList(test);
    }

    // 推荐
    private void initRecommendList() {
        recommendList = (RecyclerView) findViewById(R.id.store_recommend);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recommendList.setLayoutManager(manager);
        recommendList.addItemDecoration(new ItemSpaces());
        if (data != null) {
            adapter = new StoreRecommendAdapter(this, data.getWawaJiShowList());
            recommendList.setAdapter(adapter);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.nodata_btn:
                finish();
                break;
        }
    }

    private class ItemSpaces extends RecyclerView.ItemDecoration {

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            outRect.right = 10;
            outRect.left = 10;
            outRect.top = 10;
            outRect.bottom = 30;
        }
    }
}
